package com.fw.annotation.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fw.annotation.dao.UserDao;
import com.fw.annotation.service.UserService;

@Service // 标识这是一个 Spring 管理的 Bean，等价于 <bean id="userService" class="...">
public class UserServiceImpl implements UserService {

    //Service--->Dao
    @Autowired //根据UserDao的接口类型，自动匹配实现类，并实现注入
    private UserDao userDao;
   
    @Override
    public List<String> getAllUsers() {
        System.out.println("==Annotation UserServcie获取用户列表：===");
        return userDao.findAllUsers();
    }

    @Override
    public String getUserInfo(int id) {
        // TODO Auto-generated method stub
        return userDao.findUserById(id);
    }

    @Override
    public void registerUser(String username) {
        System.out.println("===Annotation UserServcie注册用户："+username);
        userDao.addUser(username);   
     }

    @Override
    public int getUserCount() {
        List<String> users=userDao.findAllUsers();
        return users.size();
    }

}
